from PySide6.QtWidgets import QApplication,QWidget,QPushButton,QVBoxLayout,QMainWindow,QFileDialog
from PySide6.QtGui import QPixmap,QDesktopServices
from PySide6.QtCore import Qt,QUrl
import os
import sys
from hats_detection.video_worker import worker_process_video
from hats_detection.image_worker import worker_process_image

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle('安全帽检测系统')

        #创建按钮
        self.process_video_button = QPushButton("处理视频",self)
        #绑定点击事件
        self.process_video_button.clicked.connect(self.process_video)

        #创建按钮
        self.process_image_button = QPushButton("处理图片",self)
        #绑定点击事件
        self.process_image_button.clicked.connect(self.process_image)

        #创建布局
        layout = QVBoxLayout()
        layout.addWidget(self.process_video_button)
        layout.addWidget(self.process_image_button)

        container = QWidget()
        container.setLayout(layout)
        self.setCentralWidget(container)


    def process_video(self):
        video_path,_ = QFileDialog.getOpenFileName(self,"Select Video","","Video Files (*.mp4 *.avi)")
        if video_path:
            worker_process_video(video_path)

    def process_image(self):
        image_path,_ = QFileDialog.getOpenFileName(self,"Select Image","","Image Files (*.jpg)")
        if image_path:
            worker_process_image(image_path)


if __name__ == "__main__":
    app = QApplication([])
    window = MainWindow()
    window.show()
    app.exec()